package org.cshoo.sys.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.IResponder;
	import mx.rpc.events.ResultEvent;
	
	import org.cshoo.sys.business.UserDelegate;
	import org.cshoo.sys.event.LoginEvent;
	import org.cshoo.sys.model.SysModelLocator;
	import org.cshoo.sys.model.vo.User;
	
	public class LoginCommand implements ICommand, IResponder
	{	 
		private　var　_model:SysModelLocator = SysModelLocator.getInstance();
		
		public function execute(event:CairngormEvent):void
		{
			var user:User=(event as LoginEvent).user;
			var userDelegate:UserDelegate = new UserDelegate(this);
			userDelegate.login(user);
		}
		
		public function result(event:Object):void
		{	
			var collection:ArrayCollection = (event as ResultEvent).result as ArrayCollection;
			if(collection.length > 0)
			{
				var user:User = collection.getItemAt(0) as User;
				_model.currentUser = user;
				//_model.currentUserMenuCollection =  collection.getItemAt(1) as ArrayCollection;
			}
			else
				Alert.show("用户名或密码错误");
		}
		
		public function fault(info:Object):void
		{
			Alert.show("无法连接");
		}
	}
}